<template>
  <div>
    <el-dialog
      :visible.sync="showDialog"
      append-to-body
      :close-on-click-modal="false"
      @close="close"
      destroy-on-close="true"
      width="30%"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="报价" prop="quotedPrice">
          <el-input
            v-model.number="form.quotedPrice"
            :disabled="this.isManagement"
          ></el-input>
        </el-form-item>
        <el-form-item label="报价说明" :style="this.barriershowoff">
          <el-input v-model="form.quoteDescription"></el-input>
        </el-form-item>
        <el-form-item label="调整报价" :style="this.showoff" prop="adjustOffer">
          <el-input v-model.number="form.adjustOffer"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close()">取消</el-button>
        <el-button @click="submit()" type="primary">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deepClone } from "@/util/util.js";
export default {
  name: "modifyQuotation",
  props: {
    modifyData: {},
    identity: {},
  },
  data() {
    return {
      showoff: {},
      barriershowoff: {},
      isManagement: false,
      showDialog: false,
      callback: () => {},
      form: {
        quotedPrice: "",
        quoteDescription: "",
        adjustOffer: "",
        remark: "",
      },
      transmission: {},
      query: {},
      data: [],
    };
  },
  watch: {
    modifyData() {
      this.transmission = this.modifyData;
      this.isManagement = this.identity.isManagement;
      this.showoff = this.identity.showoff;
      this.barriershowoff = this.identity.barriershowoff;
      if (this.identity.isManagement) {
        this.form.quotedPrice = this.identity.quotedPrice;
      }
    },
  },
  methods: {
    open(id, { callback }) {
      this.callback = callback;
      this.showDialog = true;
    },
    close() {
      this.showDialog = false;
      if (this.identity.isManagement) {
        this.form = {
          quotedPrice: this.identity.quotedPrice,
          adjustOffer: "",
          quoteDescription: "",
          remark: "",
        };
        return;
      }
      this.form = {
        quotedPrice: "",
        adjustOffer: "",
        quoteDescription: "",
        remark: "",
      };
    },

    submit() {
      let adjustOffervaldate = typeof this.form.adjustOffer === "number";
      let quotedPricevaldate = typeof this.form.quotedPrice === "number";
      if (
        this.form.quotedPrice == "" ||
        (this.identity.isManagement && this.form.adjustOffer == "") ||
        (this.identity.isManagement && !adjustOffervaldate) ||
        (!this.identity.isManagement && !quotedPricevaldate)
      ) {
        this.$message.warning("请输入报价，报价类型为数字");
        return;
      }
      let inquiryId = {
        ...this.transmission,
        ...this.form,
      };
      this.callback(deepClone(inquiryId));
    },
  },
};
</script>

<style></style>
